<?php

class ValidationException extends BeObjectException {

  /**
   * The collection of errors.
   * @var array
   */
  private $errors = array();
  /**
   * Regular expression to match french date format.
   * @var RegExp
   */
  protected static $__REGEXP_DATE_FR = "#^([0][0-9]|[1][0-9]|[2][0-9]|[3][01])/([0][1-9]|[1][012])/[0-9][0-9][0-9][0-9]$#";
  /**
   * Regular expression to match RNPP.
   * @var RegExp
   */
  protected static $__REGEXP_RNPP = "#^[0-9]{11}$#";
  /**
   * Regular expression to match BCE company number.
   * @var RegExp
   */
  protected static $__REGEXP_BCE_NUMBER = "#^[0-9]{10}$#";

  /**
   * Store the parameter in private of BeObjectException class.<br />
   *
   * @param string $message The message of the exception.
   * @link http://be2.php.net/manual/en/class.exception.php
   * @link http://fr2.php.net/manual/en/function.is-string.php
   * @link http://be.php.net/manual/en/function.empty.php
   */
  public function __construct($message) {
    if (is_string($message) && !empty($message))
      $this->message = $message;
    else
      throw new IllegalArgumentException("The \$message parameter must be a string.");
  }

  /**
   * Stack an error message associated to a key.
   * @param string $key The key.
   * @param string $value The message.
   * @link http://be2.php.net/manual/en/function.array-key-exists.php
   * @link http://be2.php.net/manual/en/function.array-push.php
   */
  public function addErrorMessage($key, $value) {
    if (is_string($key) && is_string($value)) {
      if (empty($this->errors[$key])) {
        $this->errors[$key] = array();
      }

      array_push($this->errors[$key], $value);
    } else {
      throw new IllegalArgumentException("The \$key or \$parameter value must be a string.");
    }
  }

  /**
   * Gets the errors.
   * @return mixed Returns the array of errros if it's not empty, FALSE otherwise.<br />
   */
  public function getErrors() {
    if (!empty($this->errors))
      return $this->errors;
    else
      return FALSE;
  }

  /**
   * Defines if there is some errors or not.<br />
   * @return boolean TRUE if there is one or more errors.<br />
   * @link http://be2.php.net/manual/en/function.count.php
   */
  public function hasErrors() {
    return count($this->errors) != 0 ? TRUE : FALSE;
  }

}
?>
